package com.cxlin.cwanandroid.ui.home.fragment

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.cxlin.base.BaseFragment
import com.cxlin.base.ext.binding
import com.cxlin.cwanandroid.R
import com.cxlin.cwanandroid.databinding.FragmentHomeTabBinding
import com.google.android.material.tabs.TabLayoutMediator

/**
 *
 * @Author: chenxunlin
 * @Date: 2024/4/25 14:14
 */
class HomeTabFragment : BaseFragment() {


    private val binding by binding<FragmentHomeTabBinding>()

    private val titleList by lazy {
        resources.getStringArray(R.array.home_tab)
    }

    private val fragments = listOf(
        HomeFragment(),
        SquareFragment(),
        ProjectTypeFragment(),
        SystemFragment(),
        NavigationFragment()
    )

    override fun getLayoutId() = R.layout.fragment_home_tab

    override fun initView() {
        initViewPager()
    }

    private fun initViewPager() {
        binding.viewPager.offscreenPageLimit = 1
        binding.viewPager.adapter = object : FragmentStateAdapter(this) {
            override fun getItemCount(): Int = titleList.size
            override fun createFragment(position: Int): Fragment = fragments[position]
        }
        TabLayoutMediator(binding.tabLayout, binding.viewPager) { tab, position ->
            tab.text = titleList[position]
        }.attach()
    }

    override fun initData() {
    }

    override fun observeStateAndEvent() {

    }

}